package com.tedu.parkinglot.user.service.impl;

import com.tedu.parkinglot.user.mapper.UserMapper;
import com.tedu.parkinglot.user.pojo.dto.UserQuery;
import com.tedu.parkinglot.user.pojo.dto.UserSaveParam;
import com.tedu.parkinglot.user.pojo.entity.User;
import com.tedu.parkinglot.user.pojo.vo.UserVO;
import com.tedu.parkinglot.user.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;
@Slf4j
@Service
public class UserServiceImpl implements UserService {
    @Autowired
    UserMapper usersMapper;
    @Override
    public List<UserVO> selectUser(UserQuery userQuery) {
        log.debug("查询用户业务:userQuery={}", userQuery);
        List<UserVO> list = usersMapper.selectUser(userQuery);
        log.debug("查询结果:list={}",list);
        return list;
    }

    @Override
    public void saveUser(UserSaveParam userSaveParam) {
        log.debug("保存用户业务:UserSaveParam={}", userSaveParam);
        User user = new User();
        BeanUtils.copyProperties(userSaveParam, user);
        user.setUpdateTime(new Date());
        usersMapper.saveUser(user);
    }

    @Override
    public void deleteUser(Long userId) {
        log.debug("删除用户业务:userId:{}", userId);
        usersMapper.deleteUser(userId);
    }
}
